package com.dhcc.bpm.modules.log.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.log.entity.GatewayLogMinute;
import com.dhcc.bpm.modules.log.service.IGatewayLogMinuteService;
import com.dhcc.bpm.modules.log.vo.GatewayLogMinuteVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @ClassName GatewayLogMinuteController.class
 * @Description  网关访问记录分钟表 控制器
 * @Author xiaFaYu
 * @Date 2020-02-03 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-system/gatewaylogminute")
@Api(value = "", tags = "接口")
public class GatewayLogMinuteController extends BladeController {

	private IGatewayLogMinuteService gatewayLogMinuteService;

	/**
	 * @Description 网关访问记录分钟表详情
	 * @Author xiafayu
	 * @Date 2020/2/24 15:26
	 * @param gatewayLogMinute
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.log.entity.GatewayLogMinute>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "网关访问记录分钟表详情", notes = "传入gatewayLogMinute")
	@ApiLog("网关访问记录分钟表详情")
	@Log(title = "网关访问记录分钟表详情",businessType = BusinessType.SELECT)
	public R<GatewayLogMinute> detail(GatewayLogMinute gatewayLogMinute) {
		GatewayLogMinute detail = gatewayLogMinuteService.getOne(Condition.getQueryWrapper(gatewayLogMinute));
		return R.data(detail);
	}

	/**
	 * @Description 网关访问记录分钟表分页
	 * @Author xiafayu
	 * @Date 2020/2/24 15:26
	 * @param gatewayLogMinute
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.log.entity.GatewayLogMinute>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "网关访问记录分钟表分页", notes = "传入gatewayLogMinute")
	@ApiLog("网关访问记录分钟表分页")
	@Log(title = "网关访问记录分钟表分页",businessType = BusinessType.SELECT)
	public R<IPage<GatewayLogMinute>> list(GatewayLogMinute gatewayLogMinute, Query query) {
		IPage<GatewayLogMinute> pages = gatewayLogMinuteService.page(Condition.getPage(query), Condition.getQueryWrapper(gatewayLogMinute));
		return R.data(pages);
	}

	/**
	 * @Description 网关访问记录分钟表分页
	 * @Author xiafayu
	 * @Date 2020/2/24 15:26
	 * @param gatewayLogMinute
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.log.vo.GatewayLogMinuteVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "网关访问记录分钟表分页", notes = "传入gatewayLogMinute")
	@ApiLog("网关访问记录分钟表分页")
	@Log(title = "网关访问记录分钟表分页",businessType = BusinessType.SELECT)
	public R<IPage<GatewayLogMinuteVO>> page(GatewayLogMinuteVO gatewayLogMinute, Query query) {
		IPage<GatewayLogMinuteVO> pages = gatewayLogMinuteService.selectGatewayLogMinutePage(Condition.getPage(query), gatewayLogMinute);
		return R.data(pages);
	}

	/**
	 * @Description 新增网关访问记录分钟表
	 * @Author xiafayu
	 * @Date 2020/2/24 15:26
	 * @param gatewayLogMinute
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增网关访问记录分钟表", notes = "传入gatewayLogMinute")
	@ApiLog("新增网关访问记录分钟表")
	@Log(title = "新增网关访问记录分钟表",businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody GatewayLogMinute gatewayLogMinute) {
		return R.status(gatewayLogMinuteService.save(gatewayLogMinute));
	}

	/**
	 * @Description 网关访问记录分钟表修改
	 * @Author xiafayu
	 * @Date 2020/2/24 15:27
	 * @param gatewayLogMinute
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "网关访问记录分钟表修改", notes = "传入gatewayLogMinute")
	@ApiLog("网关访问记录分钟表修改")
	@Log(title = "网关访问记录分钟表修改",businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody GatewayLogMinute gatewayLogMinute) {
		return R.status(gatewayLogMinuteService.updateById(gatewayLogMinute));
	}

	/**
	 * @Description 新增或修改
	 * @Author xiafayu
	 * @Date 2020/2/24 15:27
	 * @param gatewayLogMinute
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入gatewayLogMinute")
	@ApiLog("网关访问记录分钟表新增或修改")
	@Log(title = "网关访问记录分钟表新增或修改",businessType = BusinessType.INSERT)
	public R submit(@Valid @RequestBody GatewayLogMinute gatewayLogMinute) {
		return R.status(gatewayLogMinuteService.saveOrUpdate(gatewayLogMinute));
	}

	
	/**
	 * @Description 删除网关访问记录分钟表
	 * @Author xiafayu
	 * @Date 2020/2/24 15:27
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除网关访问记录分钟表", notes = "传入ids")
	@ApiLog("删除网关访问记录分钟表")
	@Log(title = "删除网关访问记录分钟表",businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(gatewayLogMinuteService.removeByIds(Func.toLongList(ids)));
	}
//	/**
//	 * 日交易量 按照时间段显示
//	 */
//	@GetMapping("/tradingVolume")
//	@ApiOperationSupport(order = 9)
//	@ApiOperation(value = "机构交易量排行", notes = "传入gatewayLogMinuteVO")
//	public R<List<TradeVolumnVo>> tradingVolume(GatewayLogMinute gatewayLogMinute) {
//
//		String nowDate = DateUtils.dateTime();
//		GatewayLogMinuteVO gatewayLogMinuteVO  = new GatewayLogMinuteVO();
//		if(! StringUtils.isEmpty(gatewayLogMinute.getEnv())) {
//			gatewayLogMinuteVO.setEnv(gatewayLogMinute.getEnv());  // 设置环境标志  0--生产 1--沙箱测试
//		}
//		gatewayLogMinuteVO.setRequestDate(nowDate);
//		List<TradeVolumnVo> tradeVoLists = new LinkedList<>();
//		tradeVoLists = gatewayLogMinuteService.countGatewayLogMinuteByDate(gatewayLogMinuteVO);
//		List<TradeVolumnVo> tradeVoListData = new LinkedList<>();
//
//		Map<Integer, TradeVolumnVo> map1 = new LinkedHashMap<Integer, TradeVolumnVo>(); // 返回
//		for(int i = 0; i < 12; i++) {
//			TradeVolumnVo vo = new TradeVolumnVo();
//			vo.setNum(0);
//			vo.setFail(0);
//			map1.put(i*2, vo);
//		}
//
//		for (TradeVolumnVo tradeVolumnVo :tradeVoLists) {
//			int num = tradeVolumnVo.getNum();
//			int hour = (int) Math.floor(Integer.valueOf(tradeVolumnVo.getRequestTime())/2);
//			int fail = tradeVolumnVo.getFail();
//			TradeVolumnVo vo = new TradeVolumnVo();
//			vo.setNum( map1.get(hour * 2).getNum() + num);
//			vo.setFail(map1.get(hour * 2).getFail() + fail);
//			map1.put(hour*2, vo);
//		}
//		TradeVolumnVo tradeVolumnVo = null;
//		for(Integer hour: map1.keySet()) {
//			tradeVolumnVo = new TradeVolumnVo();
//			Integer num = map1.get(hour).getNum();
//			Integer fail = map1.get(hour).getFail();
//			tradeVolumnVo.setRequestTime(String.valueOf(hour)+":00");
//			tradeVolumnVo.setNum(num);
//			int success = num-fail;
//			String rate = "0";
//			if(num > 0){
//				DecimalFormat df = new DecimalFormat("0");//格式化小数
//				rate = df.format((float)success/num*100);//返回的是String类型
//			}
//			tradeVolumnVo.setFail(fail);
//			tradeVolumnVo.setRate(rate+"%");
//			tradeVoListData.add(tradeVolumnVo);
//		}
//		return R.data(tradeVoListData);
//	}


}
